package shuzu

func getIntersectionNode(headA, headB *ListNode) *ListNode {
	a, b := Size(headA), Size(headB)
	if a > b {
		headA = RemoveEle(headA, a-b)
	} else {
		headB = RemoveEle(headB, b-a)
	}
	for headA != nil && headB != nil {
		if headB == headA {
			return headA
		}
		headA, headB = headA.Next, headB.Next
	}
	return nil
}

func RemoveEle(a *ListNode, times int) *ListNode {
	for times > 0 {
		a = a.Next
		times--
	}
	return a
}

/*
func Size(head *ListNode) int {
	var ans int
	for head != nil {
		ans++
		head = head.Next
	}
	return ans
}
*/
